import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';
import 'package:loading/indicator/ball_pulse_indicator.dart';
import 'package:loading/loading.dart';
import 'package:yw_bapp/widgets/tip_pop_widget.dart';

void showAlertDialog(BuildContext context, @required String info,
    {String title = '温馨提示',
    String cancelText = '取消',
    String confirmText = '确定',
    Function cancelFunc,
    Function confirmFunc,
    bool onlyConfirm}) {
  showDialog<Null>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AnimationTipPop(
            title: title,
            info: info,
            cancelText: cancelText,
            confirmText: confirmText,
            cancelFunc: cancelFunc,
            confirmFunc: confirmFunc,
            onlyConfirm: onlyConfirm);
      });
}

void showLoadingDialog(
  BuildContext context,
) {
  showDialog<Null>(
    context: context,
    barrierColor: Color.fromRGBO(255, 255, 255, 0.3),
    barrierDismissible: false,
    builder: (BuildContext context) {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Loading(
                indicator: BallPulseIndicator(),
                size: 100.0,
                color: ColorUtil.color("#FFC49226")),
          ],
        ),
      );
    },
  );
}

Widget iosTipTop(BuildContext context, String info,
    {title: '温馨提示',
    cancelText: '取消',
    confirmText: '确认',
    confirmColor,
    Function cancelCallback,
    Function confirmCallback}) {
  return CupertinoAlertDialog(
    title: Text('$title'),
    content: Container(
      margin: EdgeInsets.only(top: 8),
      child: Text('$info'),
    ),
    actions: [
      CupertinoDialogAction(
        child: Text(
          '$cancelText',
          style: TextStyle(color: Colors.grey),
        ),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      CupertinoDialogAction(
        child: DefaultTextStyle(
          child: Text(
            '$confirmText',
            style: TextStyle(color: confirmColor),
          ),
          style: TextStyle(color: Colors.blue),
        ),
        onPressed: () {
          Navigator.pop(context);
          confirmCallback();
        },
      )
    ],
  );
}
// iosTipTop的使用方式：
// showCupertinoDialog(
//  context: context,
//  builder: (context) {
//   return iosTipTop(context,'查看明细',cancelCallback: (){print("点击取消了");});
//   });
